﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FPCLib;

namespace IsaControl
{
	public class RuleControl : IDisposable
	{
		private FPC root;
		private FPCPolicyRules rules;
		private bool real;

		public RuleControl(bool real)
		{
			this.real = real;

			if (real)
			{
				this.root = new FPC();
				var arr = root.GetContainingArray();
				this.rules = arr.ArrayPolicy.PolicyRules;
			}
		}

		public bool IsRuleEnabled(string rulename)
		{
			if (real)
				return this.rules.Item(rulename).Enabled;
			else
				return true;
		}

		public bool AlterRule(string rulename, bool newstate)
		{
			if (!real) return true;

			var r = this.rules.Item(rulename);
			if (r.Enabled == newstate) return false;

			r.Enabled = newstate;
			r.Save();

			return true;
		}

		public void Dispose()
		{
			// don't know if this is needed
			this.rules = null;
			this.root = null;
		}
	}
}
